﻿#region Copyright Notice
// 
// 
// Copyright (c) 2009-2010 Anindya Chatterjee
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// 
// 
#endregion
using Event.Plugin.Configuration;
using Event.Plugin.Utility;

namespace Event.Plugin
{
    /// <summary>
    /// A delegate to an event which will signal that listening is successful
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    public delegate void Signal(object sender, SignalArgs args);

    /// <summary>
    /// Main interface for each event
    /// </summary>
    public interface IEvent
    {
        /// <summary>
        /// Event id, it should be unique
        /// </summary>
        int Id { get; set; }

        /// <summary>
        /// Indicates if an event is scheduled or not
        /// </summary>
        bool IsScheduled { get; }

        /// <summary>
        /// Indicates that an event must keep on listening after successful capture
        /// </summary>
        bool Loop { get; set; }

        /// <summary>
        /// The time interval for which EventLogic will be executed
        /// </summary>
        int ListeningInterval { get; set; }

        /// <summary>
        /// The condition is to be satisfied to run a scheduled event
        /// </summary>
        ICondition Condition { get; set; }

        /// <summary>
        /// The event host for this event
        /// </summary>
        IEventHost Host { get; set; }

        /// <summary>
        /// Notifier handle for the event
        /// </summary>
        INotifier UserNotifier { get; set; }

        /// <summary>
        /// Event specific settings
        /// </summary>
        IEventSettings EventSettings { get; set; }

        /// <summary>
        /// Gain access to the main application settings
        /// </summary>
        ISettings ApplicationSettings { get; set; }

        /// <summary>
        /// Name of the event
        /// </summary>
        string Name { get; set; }

        /// <summary>
        /// Signaled the listener that listening is completed
        /// </summary>
        bool ListeningComplete { get; set; }

        /// <summary>
        /// Handle any unhandled exception occurred in the event
        /// </summary>
        UnhandledException UnhandledExceptionHandler { get; set; }

        /// <summary>
        /// Signaled the listener that listening is completed
        /// </summary>
        event Signal Listened;

        /// <summary>
        /// Put your business logic here which will execute after every ListeningInterval of time
        /// </summary>
        void EventLogic();

        /// <summary>
        /// Starts listening the EventLogic
        /// </summary>
        void StartListening();

        /// <summary>
        /// True if the condition is satisfied for a scheduled event, otherwise false
        /// </summary>
        /// <returns></returns>
        bool IsConditionSatisfied();

        /// <summary>
        /// Call it when to notify that the condition is satisfied
        /// </summary>
        void Notify();

        /// <summary>
        /// Execute it after one listening is complete
        /// </summary>
        void EndListening();

        /// <summary>
        /// Initializes settings and all, of an event
        /// </summary>
        void InitializeEvent();
    }
}